package com.wjh.www.controller;

import com.wjh.www.annotation.spring.Autowired;
import com.wjh.www.annotation.spring.Component;
import com.wjh.www.annotation.springmvc.RequestBody;
import com.wjh.www.annotation.springmvc.RequestMapping;
import com.wjh.www.annotation.springmvc.RequestParam;
import com.wjh.www.dao.mapper.UserMapper;
import com.wjh.www.entity.dto.CommonResult;
import com.wjh.www.entity.po.Clazz;
import com.wjh.www.entity.po.User;
import com.wjh.www.entity.vo.ClazzInfoVo;
import com.wjh.www.entity.vo.UserInfoVo;
import com.wjh.www.service.impl.ClazzServiceImpl;

import javax.servlet.annotation.WebServlet;
import java.util.List;

/**
 * 班级相关接口
 *
 * @author wjh
 * @date 2021/9/11 13:53
 * @Package com.wjh.anyview.controller
 */
@WebServlet("/anyview/clazz/*")
@Component
public class ClazzController extends DispatcherController {
    @Autowired
    private ClazzServiceImpl clazzService;
    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/addClazz")
    CommonResult<?> addClazz(@RequestBody Clazz clazz) {
        return clazzService.addClazz(clazz);
    }

    @RequestMapping("/deleteClazzById")
    CommonResult<?> deleteClazzById(@RequestParam("clazzId") Long clazzId) {
        return clazzService.deleteClazzById(clazzId);
    }

    @RequestMapping("/queryClazzById")
    CommonResult<List<UserInfoVo>> queryClazzById(@RequestParam("clazzId") Long clazzId) {
        return clazzService.queryClazzById(clazzId);
    }

    @RequestMapping("/studentChangeClazz")
    CommonResult<?> studentChangeClazz(@RequestParam("clazzId") Long clazzId, @RequestParam("num") String num) {
        User userSelect = new User();
        userSelect.setNum(num);
        User user = userMapper.selectOneByFields(userSelect);
        if (user == null) {
            return CommonResult.operateFailWithMessage("该学号不存在本系统或不是学生的学号！");
        }
        return clazzService.studentChangeClazz(clazzId, user.getId());
    }

    @RequestMapping("/deleteStudentInClazz")
    CommonResult<?> deleteStudentInClazz(@RequestParam("studentId") Long studentId) {
        return clazzService.deleteStudentInClazz(studentId);
    }

    @RequestMapping("/queryAllClazz")
    CommonResult<List<ClazzInfoVo>> queryAllCourse(@RequestParam("adminId") Long adminId) {
        return clazzService.queryAllClazz();
    }
}
